<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="css/scan/scanItem.css" />
	</head>

	<body>
		<div id="controller">
			<header class="mui-bar mui-bar-nav">
				<a v-show='!back' class="mui-icon mui-icon-left-nav mui-pull-left" @click="toScan('scan.html')">扫一扫</a>
				<a v-show='back' class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left">食药地图</a>
				<h1 class="mui-title">{{ name }}</h1>
			</header>
			<div class="mui-content">
				<div class="msgItems">
					<p class="title">基本信息</p>
					<div class="itemContent">
						<p>所属行业：<span>{{ enter.sshy }}</span></p>
						<p>经营/生产地址：<span>{{ adr.province }}{{ adr.state }}{{ adr.city }}{{ enter.oaway }}</span></p>
						<p>许可证号：<span>{{ license.number }}</span></p>
						<p>有效期至：<span>{{ license.endtime }}</span></p>
					</div>
				</div>
				<div class="msgItems">
					<p class="title">法定代表人(负责人)信息</p>
					<div class="itemContent">
						<p>法定代表人(负责人)：<span>{{ leg.name }}</span></p>
						<p>手机号码：<span>{{ leg.phone }}</span></p>
						<p>身份证号码：<span>{{ leg.idcard }}</span></p>
					</div>
				</div>
			</div>
			<div v-show='!back' class="detail">
				<a href="#popover" id="openPopover"></a>
			</div>
			<div id="popover" class="mui-popover">
				<ul class="mui-table-view">
					<li class="item">
						<a href="javascript:;" @click="toAdd('supervisionAdd.html',id)"><i class="jiandu"></i><span>新增日常监督</span></a>
					</li>
					<li class="item">
						<a href="javascript:;" @click="toAdd('penalizeAdd.html',id)"><i class="chufa"></i><span>新增行政处罚</span></a>
					</li>
					<li class="item">
						<a href="javascript:;" @click="local"><i class="dingwei"></i><span>定位</span></a>
					</li>
				</ul>
			</div>
		</div>
	</body>
	<script src="js/lib/jquery-1.11.0.js" type="text/javascript" charset="utf-8"></script>
	<script src="js/mui.min.js"></script>
	<script src="js/common/server_commonFun.js" type="text/javascript" charset="utf-8"></script>
	<script src="js/common/rutour.js" type="text/javascript" charset="utf-8"></script>
	<script src="js/lib/vue.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
		mui.init({
			swipeBack: false //启用右滑关闭功能
		});
		mui('body').on('shown', '.mui-popover', function(e) {
			$('.detail').css({
				'backgroundImage': 'url(images/close.png)'
			})
		});
		mui('body').on('hidden', '.mui-popover', function(e) {
			$('.detail').css({
				'backgroundImage': 'url(images/detial.png)'
			})
		});
		var vm = new Vue({
			el: '#controller',
			data: {
				dataObj: {},
				name: '',
				id: '',
				token: '',
				license:'',
				adr:'',
				leg:'',
				enter:'',
				back:false
			},
			mounted: function() {
				this.init()
			},
			methods: {
				init: function() {
					mui.plusReady(function() {
						var currentView = plus.webview.currentWebview(); // 获取 当前webview
						currentView.show('slide-in-right', 300); // 显示当前webview (方式,时间)
						plus.nativeUI.closeWaiting(); // 关闭系统 loading 等待框
						var current = plus.webview.currentWebview();
						vm.id = current.rid;

						vm.back = current.backs;
						console.log(vm.back);
						vm.token = plus.storage.getItem('token');
						mui.ajax(rutour.scan.baseInfo + vm.token, {
							dataType: 'json',
							type: 'get',
							data: {
								id: vm.id
							},
							success: function(data) {
								if(data.code == 200) {
									console.log(data)
									vm.dataObj = data.data;
									vm.license = data.data.license||'';
									vm.adr = data.data.adr||'';
									vm.enter = data.data.enter||'';
									vm.leg = data.data.leg||'';
									vm.name = data.data.enter.name
								} else {
									mui.toast(data.msg)
								}
							},
							error: function() {
								mui.toast('联系管理员去吧~')
							}
						})
					})
				},
				toAdd: function(urlName, id) {
					mui('#openPopover').popover('toggle');
					$('div.mui-backdrop').remove();
					var $contentW = localStorage.getItem('$contentW'),
						$menuLeftW = localStorage.getItem('$menuLeftW');
					mui.openWindow({
						url: urlName,
						id: urlName,
						styles: {
							left: $menuLeftW,
							width: $contentW,
						},
						extras: {
							ywid: id
						}
					});
				},
				local: function() {
					mui('#openPopover').popover('toggle');
					$('div.mui-backdrop').remove();
					mui.plusReady(function() {
						plus.geolocation.getCurrentPosition(function(p) {
							var w = p.coords.latitude,
								j = p.coords.longitude;
							console.log('j:' + j + ",w:" + w)
							mui.ajax(rutour.scan.location + vm.token, {
								dataType: 'json',
								type: 'get',
								data: {
									ywid: vm.id,
									longitude: j,
									latitude: w
								},
								success: function(data) {
									if(data.code == 200) {
										mui.toast(data.msg);
									} else {
										mui.toast(data.msg)
									}
								},
								error: function() {
									mui.toast('联系管理员去吧~')
								}
							})
						}, function(e) {
							mui.toast('定位失败，请检查当前设备网络或定位权限')
						})
					})
				},
				toScan: function(urlName) {
					var nwaiting = plus.nativeUI.showWaiting();
					webviewShow = plus.webview.create(urlName, urlName);
					mui.plusReady(function() {
						var wo = plus.webview.currentWebview().opener();
						setTimeout(function() {
							wo.close();
						}, 300)
					})
				}
			}
		})
	</script>

</html>